#!/bin/bash
# @@@ START COPYRIGHT @@@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
# @@@ END COPYRIGHT @@@

xclient=$1
shift

attach=0
if [ "$1" = "-attach" ]; then
	attach=1
fi
if [ "$2" = "-attach" ]; then
	attach=1
fi
if [ "$3" = "-attach" ]; then
	attach=1
fi
if [ "$4" = "-attach" ]; then
	attach=1
fi
if [ "$5" = "-attach" ]; then
	attach=1
fi

if [ $attach = 1 ]; then
	sqshell=$TRAF_HOME/sql/scripts/sqshell
	if [ -r $sqshell ]; then
		nodes=`grep -w SQ_VIRTUAL_NODES $sqshell`
		if [ $? != 0 ]; then
			echo "SQ_VIRTUAL_NODES not found in $sqshell"
			exit 1
		fi
		nid=`grep -w SQ_VIRTUAL_NID $sqshell`
		if [ $? != 0 ]; then
			echo "SQ_VIRTUAL_NID not found in $sqshell"
			exit 1
		fi
		eval $nodes
		eval $nid
		dir=`dirname $0`
		export PATH=$PWD:$PATH
		$dir/$xclient -attach $* -client
	else
		echo "$$sqshell does not exist"
	fi
else
	goshell31 $xclient $*
fi

